// import * as types from '@/store/mutation-type.js'
import * as CONSTANTS from '@/constants/index'
import REQUEST from '@/api/index.js'
import ROUTER from '@/router/index'
// import STORE from '@/store/index'
import { API_BASEPREFIX } from '@/constants/index'
import { Toast } from 'vant'

export default {
  /**
   * 异步获取common token
   */
  [CONSTANTS.DISPATCH_GETASYNC_COMMONTOKEN]: async ({ commit }, payload) => {
    try {
      const params = {
        appKey: CONSTANTS.VAR_APPKEY,
        appSecret: CONSTANTS.VAR_APPVALUE,
      }

      const { data } = await REQUEST[CONSTANTS.API_GET_COMMONTOKEN](params)
      if (!data.success) throw new Error(data.info)
      const resData = data.data
      
      commit(CONSTANTS.COMMIT_UPDATE_COMMONSTATE, {
        key: 'token',
        value: resData,
      })

      return resData;
    } catch (err) {
      console.log(err)
      Toast.fail(err.message)
    }
  },
}
